<template id="forgot_password">
	<div class="forgot_password">

		<!--登陆标题-->
		<div class="login_title">
			<p>登陆</p>
		</div>
		<!--登陆标题结束-->

		<!--请输入手机号/密码-->
		<div class="login_entry">

			<!--请输入手机号-->
			<div class="login_tel">
				<div class="login_tel_left">
					<img src="../../assets/images/login/phone.png" />
					<input type="number" id="messageInput" placeholder="请输入手机号" value="" v-model="phone" @change="phhotoChange($event)" />
				</div>
				<div class="login_tel_right" @click="model()">
					<img src="../../assets/images/login/clear.png">
				</div>
			</div>

			<!--请输入短信验证-->
			<div class="login_vaildate">
				<div class="login_vaildate_left">
					<img src="../../assets/images/login/check.png" />
					<input type="number" name="" id="" placeholder="请输入短信验证" v-model="code" />
				</div>
				<div class="login_vaildate_right" @click="Code()">
					<button :disabled="!sendAuthCode" :style="{background: sendAuthCode ? '#2d8f90' : '#ccc'}"> {{sendAuthCode ? '获取验证码' : '重新获取' + auth_time + '秒' }}</button>
				</div>

			</div>

		</div>
		<!--请输入手机号/密码结束-->

		<!--登陆按钮-->
		<div class="login_press" @click.stop="Landed()">
			<router-link to=""><button>登陆</button></router-link>
		</div>
		<!--登陆按钮结束-->

		<!--未注册手机验证码后自动注册-->
		<div class="login_jin">
			未注册手机验证码后自动注册
		</div>

		<!--用户协议及隐私政策-->

			<!--微信登陆-->
		<div class="login_weixin" @click="weixin()">
			<p>其他方式登陆</p>
			<a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx804dd171dbba7021&redirect_uri=http://yogahome.top/ygweb/%23/weixin&response_type=code&scope=snsapi_userinfo&state=yghome2018#wechat_redirect">
				<img src="../../assets/images/login/wechat.png" />
			</a>
		</div>

		<!--微信登陆结束-->



		<div class="edit_policy">
			<img src="../../assets/images/main/pitch_on.png" />
			<span>用户协议及隐私政策</span>
		</div>
		<!--用户协议及隐私政策结束-->

	</div>
</template>

<script>
	export default {
		name: 'forgot_password',
		components: {},
		data() {
			return {
				sendAuthCode: true,
				/*布尔值，通过v-show控制显示‘获取按钮’还是‘倒计时’ */
				auth_time: 0,
				/*倒计时 计数器*/
				phone: "", //手机号
				code: "", //验证码
				coachid: "",
				sessionid: '',
				select_address: '',
				about_coach:'',
				main:'',
				coachid:this.$route.query.coachid
			}
		},

		created() {
				this.select_address = this.$route.query.select_address;
				this.about_coach = this.$route.query.about_coach;
				this.main = this.$route.query.main;
				// console.log(this.select_address,this.about_coach)
				// console.log(this.coachid)
				var zt=this.$route.query.zt;
                if(zt == 1){
                    this.$router.push({
                        path:'/appointment_coach',
                        query:{
                        }
                        })
                }
		},
		mounted(){

		},
		methods: {
			model() {
				this.phone = "";

			},
			phhotoChange(e) {
				this.phone = e.target.value;
			},
			Code() {
				let re = /^1\d{10}$/;
				let _this = this;
				if(this.phone) {
					if(re.test(_this.phone)) {
						var phone = _this.phone;
						let obj = {
							phone
						};
						let qs = require('qs');
						_this.$axios.post("/yujia/user/captcha", qs.stringify(obj), {
							headers: {
								'Content-Type': 'application/x-www-form-urlencoded'
							},
						}).then((response) => {
							_this.sendAuthCode = false;
							_this.auth_time = 60;
							var auth_timetimer = setInterval(() => {
								_this.auth_time--;
								if(_this.auth_time <= 0) {
									_this.sendAuthCode = true;
									clearInterval(auth_timetimer);
								}
							}, 1000);

						}).catch(function(error) {
							console.log(error);
						});

					} else {
						_this.sendAuthCode = true;
						mui.alert('手机号格式不正确,请重新输入')
					}

				} else {
					_this.sendAuthCode = true;
					mui.alert('请输入手机号码')
				}

			},
			Landed() {
				let _this = this
				if(this.phone) {
					let phone = this.phone; //手机号
					let code = this.code; //验证码
					let obj = {
						phone,
						code,

					};

					if(this.phone == "") {

					} else {

					}

					let qs = require('qs');
					this.$axios.post("/yujia/user/login", qs.stringify(obj), {
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},

					}).then(function(response) {
						_this.sessionid = response.data.data.sessionid;
						window.sessionStorage.setItem('SESSION_ID', JSON.stringify(response.data.data));
						_this.$store.commit('getUser', _this.sessionid)
						document.cookie = "sessionid=" + response.data.data.sessionid;
						window.localStorage.setItem('sessiond',JSON.stringify(response.data.data))
						if(response.data.code =='0'){
						  if(response.data.data.defaultaddress!=null) {
                document.cookie = "city=" + response.data.data.defaultaddress.city;
                document.cookie = "detail_addr=" + response.data.data.defaultaddress.detail_addr;
                document.cookie = "area=" + response.data.data.defaultaddress.area;
                document.cookie = "ctime=" + response.data.data.defaultaddress.ctime;
                document.cookie = "edifice=" + response.data.data.defaultaddress.edifice;
                document.cookie = "gender=" + response.data.data.defaultaddress.gender;
                document.cookie = "id=" + response.data.data.defaultaddress.id;
                document.cookie = "is_default=" + response.data.data.defaultaddress.is_default;
                document.cookie = "lat=" + response.data.data.defaultaddress.lat;
                document.cookie = "lng=" + response.data.data.defaultaddress.lng;
                document.cookie = "phone=" + response.data.data.defaultaddress.phone;
                document.cookie = "street=" + response.data.data.defaultaddress.street;
                document.cookie = "phone=" + response.data.data.defaultaddress.phone;
                document.cookie = "province=" + response.data.data.defaultaddress.province;
                document.cookie = "userid=" + response.data.data.defaultaddress.userid;
                document.cookie = "username=" + response.data.data.defaultaddress.username;
                document.cookie = "utime=" + response.data.data.defaultaddress.utime;
                window.localStorage.setItem('lat', JSON.stringify(response.data.data.defaultaddress.lat))
                window.localStorage.setItem('lng', JSON.stringify(response.data.data.defaultaddress.lng))
              }
						//   console.log("状态码为0")
							var oneselect_address=_this.select_address
							var about_coach=_this.about_coach
							var main=_this.main
							if(oneselect_address != undefined){
								getpush(oneselect_address)
							}else if(about_coach != undefined){
							  console.log("about_coach");
							  console.log(document.cookie.length)
							  if(document.cookie.length>50){
                  getpush(about_coach)
                }else{
                  _this.$router.push({
                    path: "/new_address",
                    query:{
                      about_coach: about_coach,
                      coachid: _this.coachid
                    }
                  })
                }
							}else if(main !=undefined){
                console.log("main");
								getpush(main)
							}else{
							  getpush("about_class")
              }
						    function getpush(oneselect_address){
								console.log(oneselect_address)
								_this.$router.push({
									path: "/"+oneselect_address,
									query:{
										coachid: _this.coachid
									}
								})
								mui.alert(response.data.message)
							}
						}
					}).catch(function(error) {
						console.log(error);
					})
				} else {
					mui.alert("请输入手机号码")
				}

			},

		},

	}
</script>

<style scoped>
	@import "../../assets/css/forgot_password.css";
</style>
